package com.hangxin.commons.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.hangxin.commons.dao.SysAccessoryDao;
/**
 * 
 * 类名称：SysAccessoryDaoImpl.java
 * <P/>
 * 类描述： 无
 * <P/>
 * 创建时间：2014年5月15日
 * <P/>
 * 创建人： 杨春豪
 * <P/>
 * 联系方式： 550813852@qq.com
 * <P/>
 * 修改人：无
 * <P/>
 * 修改时间：无
 * <P/>
 * 修改备注：无
 * <P/>
 * 版本：v1.0
 *
 */
@Repository
public class SysAccessoryDaoImpl extends BasicDaoImpl implements
		SysAccessoryDao {


	@Override
	public List<Map<String, Object>> findAllSysAccessory(Object[] params) {
		String sql = "select * from systemaccessories where FILEOWNERSHIP = ? and FILEID =?";
		List<Map<String, Object>> listmap = null;
		try
		{
			listmap = this.findMap(sql, params);
		} catch (Exception e)
		{
			e.printStackTrace();
			logger.error("查询附件出错！");
		}
		return listmap;
	}
	
	@Override
	public Integer saveSysAccessories01(Object[] params) {
		String sql = "insert into systemaccessories (id,fileid,fileownership,filepath,filename,storename) values (sysaccessory_seq.nextval,?,?,?,?,?)";
		return this.save(sql, params);
	}


	@Override
	public Integer delSysAccessories(Object[] params) {
        String sql ="delete from systemaccessories t where t.id = ?";
		return this.save(sql, params);
	}
	
	@Override
	public List<Map<String,Object>> getNewTopic(Object[] params){
		String sql =  "\n" +
				  "select *\n" + 
				  "  from (select A.*, rownum rn\n" + 
				  "          from (select  t.tid tid,\n" + 
				  "                       (select l.username\n" + 
				  "                          from logininfo l\n" + 
				  "                         where l.id = t.userid) username,\n" + 
				  "                       t.title title,\n" + 
				  "                       t.viewnum viewnum,\n" + 
				  "                       t.subjectid subjectid,\n" + 
				  "                       t.createdate createdate,\n" + 
				  "                       r.createdate lastcreatedate,\n" +
				  "                       (select l.username from logininfo l where l.id=r.userid) lastrplyusername,\n" +
				  "                       (select count(*) from reply r where r.tid=t.tid) countnum\n" + 
				  "                  from topic t left join reply r on t.lastrplyid=r.rid\n and t.tid = r.tid" + 
				  "                 where   t.status='0' order by t.createdate desc) A\n" + 
				  "         where rownum <5)\n" + 
				  " where rn > 0";return this.findMap(sql, params);
	}
	
}
